#include"DynamicArray.h"
#include<iostream>

DynamicArray::DynamicArray():size(0),capacity(10)
{
    a=new int[capacity];
}

DynamicArray::~DynamicArray()
{
    delete []a; 
}

DynamicArray::DynamicArray(const DynamicArray &array)
{
    size=array.size;
    capacity=array.capacity;
    a=new int{capacity};
    for(int i=0;i<size;i++)
    {
        a[i]=array.a[i];
    }

}
  void DynamicArray::operator=(const DynamicArray &array)
        {
                delete []a;
                size=array.size;
                capacity=array.capacity;
                a=new int{capacity};
                for(int i=0;i<size;i++)
                {
                    a[i]=array.a[i];
                }   

        }

void DynamicArray::Insert(int element)
{
    if(size==capacity)
    {
        capacity *=2;
        int *newp=new int[capacity];
        for(int i=0;i<size;i++)
        {
            newp[i]=a[i];
        }
        delete []a;
        a=newp;

    }
    a[size++]=element;
}
void DynamicArray::show()
{
    for(int i=0;i<size;i++)
    {
        std::cout<<a[i]<<" ";
    }
    std::cout<<std::endl;
}
